package com.tushu.service;

import com.tushu.Login;
import com.tushu.dao.BookDao;
import com.tushu.model.Book;
import com.tushu.model.Student;

import java.util.Scanner;

public class SearchService {
    private static BookDao bookDao = new BookDao();
    public static void searchBook() {
        System.out.println("检索方式：1.书名  2.ISBN码");
        System.out.println("请选择：");
        Scanner s1 = new Scanner(System.in);
        int option = s1.nextInt();
        if (option == 1) {
            System.out.print("请输入书名：");
            Scanner s2 = new Scanner(System.in);
            String bookName = s2.nextLine();
            Book book = bookDao.getBookByName(bookName);
            showResult(book);
        } else if (option == 2) {
            System.out.print("请输入图书ISBN：");
            Scanner s3 = new Scanner(System.in);
            String isbn = s3.nextLine();
            Book book = bookDao.getBookByIsbn(isbn);
            showResult(book);
        } else {
            System.out.println("输入错误！请重新输入！");
            searchBook();
        }
    }

    public static void showResult(Book book) {
        System.out.println("--------------------");
        System.out.println("查找结果如下：");
        System.out.println("id" + "\t\t" + "isbn" + "\t\t" + "书名" + "\t\t" + "作者" + "\t\t" + "出版社" + "\t\t" + "馆藏数量");
        System.out.println(book.getId() + "\t\t" + book.getIsbn() + "\t\t" + book.getBookName() + "\t\t" + book.getAuthor() + "\t\t" + book.getPublisher() + "\t\t" + book.getNum());
        System.out.println("-------1.重新输入查询  2.返回------");
        Scanner scanner = new Scanner(System.in);
        int i = scanner.nextInt();
        if (i == 1) {
            searchBook();
        } else if (i == 2) {
            Login.StudentMenu();
        } else {
            System.out.println("输入错误！");
        }

    }
}
